package cn.explink.eap.siphon.util;

import java.util.ArrayList;
import java.util.List;

import cn.explink.eap.web.cgform.entity.enhance.CgformEnhanceJsEntity;

/**
 * 方法抽取工厂
 * @author hedy
 * @date 2015-1-13 12:11
 */
public class SiphonMethodFactory {
	
	/**
	 * 获取应用js
	 * @author hedy
	 * @return 添加<script></script>标签之后的数据
	 */
	public static List<String> getJavaScriptList(List<CgformEnhanceJsEntity> list) {
		List<String> javaScriptList = new ArrayList<String>();
		if (list == null || list.size() <= 0) {
			javaScriptList.add("");
			return javaScriptList;
		}
		for (CgformEnhanceJsEntity entity : list) {
			StringBuffer sb = new StringBuffer();
			//<script type="text/javascript" src=""></script>
			sb.append("<script type='text/javascript' src='").append(entity.getPath()).append("'></script>");
			javaScriptList.add(sb.toString());
		}
		return javaScriptList;
	}
	
	/**
	 * 获取应用扩展js
	 * @param list 扩展js
	 * @param addScript 是否添加script标签
	 * @return js 列表数据
	 */
	public static List<String> getJavaScriptList(List<CgformEnhanceJsEntity> list, boolean addScript) {
		List<String> javaScriptList = new ArrayList<String>();
		if (list == null || list.size() <= 0) {
			javaScriptList.add("");
			return javaScriptList;
		}
		if (addScript) {
			for (CgformEnhanceJsEntity entity : list) {
				StringBuffer sb = new StringBuffer();
				//<script type="text/javascript" src=""></script>
				sb.append("<script type='text/javascript' src='").append(entity.getPath()).append("'></script>");
				javaScriptList.add(sb.toString());
			}
		} else {
			for (CgformEnhanceJsEntity entity : list) {
				StringBuffer sb = new StringBuffer();
				//<script type="text/javascript" src=""></script>
				sb.append(entity.getPath());
				javaScriptList.add(sb.toString());
			}
		}
		return javaScriptList;
	}
}
